//
//  DiscoverClassifyTableViewCellSecond.m
//  XYFMApp
//
//  Created by 岁变 on 16/9/7.
//  Copyright © 2016年 岁变. All rights reserved.
//

#import "DiscoverClassifyTableViewCellSecond.h"
#import "XYMacro.h"

@interface DiscoverClassifyTableViewCellSecond () <UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionViewFlowLayout *layout;
@property (nonatomic, strong) NSArray *arr;

@end

@implementation DiscoverClassifyTableViewCellSecond

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        _arr = @[@"1", @"2", @"3"];
        _picImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"catinfo_fire"]];
        [self.contentView addSubview:_picImageView];
        
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithRed:0.97 green:0.27 blue:0.12 alpha:1.00];
        [self.contentView addSubview:_lineView];
        
        _labelOne = [[UILabel alloc] init];
        _labelOne.textColor = [UIColor redColor];
        _labelOne.text = @"最热栏目榜";
        _labelOne.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_labelOne];
        
        _labelTwo = [[UILabel alloc] init];
        _labelTwo.textColor = [UIColor colorWithRed:0.44 green:0.45 blue:0.47 alpha:1.00];
        _labelTwo.text = @"TOP 3";
        [self.contentView addSubview:_labelTwo];
        
        _layout = [[UICollectionViewFlowLayout alloc] init];
        _layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        
        _collectionView = [[BaseCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:_layout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.showsVerticalScrollIndicator = NO;
        [self.contentView addSubview:_collectionView];
        [_collectionView registerClass:[DiscoverClassifyCollectionViewCellFourth class] forCellWithReuseIdentifier:@"DiscoverClassifyCollectionViewCellFourth"];
        
    }
    return self;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 3;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    DiscoverClassifyCollectionViewCellFourth *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DiscoverClassifyCollectionViewCellFourth" forIndexPath:indexPath];
    cell.countLabel.text = [_arr objectAtIndex:indexPath.row];
    cell.model = [_modelArr objectAtIndex:indexPath.row];
    return cell;
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    VCOfClassify *classifyVC = (VCOfClassify *)self.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder;
    VCOfDiscoverList *nextVC = [[VCOfDiscoverList alloc] init];
    if (_count == 1) {
        ClassifyModelFirstTopMusics *model = [_modelArr objectAtIndex:indexPath.row];
        nextVC.item_id = [NSString stringWithFormat:@"%ld", model.item_id];
    }
    if (_count == 2) {
        ClassifyModelFirstNewMusics *model = [_modelArr objectAtIndex:indexPath.row];
        nextVC.item_id = [NSString stringWithFormat:@"%ld", model.item_id];
    }
    [classifyVC.navigationController pushViewController:nextVC animated:YES];
}



- (void)setModelArr:(NSArray *)modelArr {
    
    _modelArr = [NSArray array];
    _modelArr = modelArr;
}



- (void)layoutSubviews {
    
    [super layoutSubviews];
    [_picImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(20);
        make.top.equalTo(self.contentView.mas_top).with.offset(15);
        make.width.mas_offset(12);
        make.height.mas_offset(20);
    }];
    
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
        make.top.equalTo(_picImageView.mas_bottom).with.offset(15);
        make.height.mas_offset(1);
    }];
    
    [_labelOne mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_picImageView.mas_right).with.offset(20);
        make.top.equalTo(self.contentView.mas_top).with.offset(15);
        make.width.mas_offset(80);
        make.height.mas_offset(20);
    }];
    
    [_labelTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_labelOne.mas_right).with.offset(20);
        make.top.equalTo(self.contentView.mas_top).with.offset(15);
        make.height.mas_offset(20);
        make.width.mas_offset(50);
    }];
    
    _layout.itemSize = CGSizeMake(self.contentView.frame.size.width, (self.contentView.frame.size.height - 80) / 3);
    _layout.minimumInteritemSpacing = 10;
    _layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    
    [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
        make.top.equalTo(self.contentView.mas_top).with.offset(60);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(0);
    }];
    
}



@end
